'''
1.读取message.txt。世界杯的信息。键盘上输入年份，输出对应的举办地和冠军国。如果没有举办，就输出没有举办
	思路：读取本地文件的数据：
		[],{}
'''
file_path = "message.txt"
f = open(file_path, mode="r", encoding='utf-8')
list_content = f.readlines()
print(type(list_content))
dict_area = {}
dict_country = {}
for i in list_content:  # 遍历列表
    # print(i)
    list_split = i.split("|")
    dict_area[list_split[0]] = list_split[1]
    dict_country[list_split[0]] = list_split[2]
f.close()

print(dict_area)
print(dict_country)

flag = True
while flag is not 'q':
    year = input('请输入你要查询的年份:\n')
    flag = year
    # print('%s 年运动会,举办地是 %s,冠军国是 %s'%(year,dict_area[year],dict_country.get(year)))
    # print('%s 年运动会,举办地是 %s,冠军国是 %s' % (year, dict_area.get(year), dict_country.get(year)))
    try:
        print('%s 年运动会,举办地是 %s,冠军国是 %s' % (year, dict_area[year], dict_country.get(year)))
    except Exception as e:
        print(e.args)
        print('%s 年没有举办运动会' % year)

# str1 = '1958|瑞典|巴西'
# # 一个字符串中是否包含某个字串
# # print(str1.__contains__('hh'))
# # print(str1.startswith('ssf'))
# print(str1.endswith('KK'))

# res = str1.split('|')
# print(res)
